#include<iostream>
using namespace std;
#include<fstream>
#include<string>

const int modNum = 1000000007;

//dp[0][][] false ; dp[1][][] true
int dp[2][505][505];


class Solution
{
public:
    int getNum(const string& str, const string& desire) {
        bool bdesire = desire == "true" ? true : false;
        // int ret = recursion(str, 0, str.length()-1, bdesire);
        int ret = dynamicPlan(str, bdesire);
        cout << ret << endl;
        return ret;
    }

    //超时 递归
    int recursion(const string& str, int L, int R, bool desire) {
        if(L > R) {
            return 0;
        }
        // cout << "L:" << L << " R:" << R << endl;
        if(L == R) {
            int dint = desire ? 1 : 0;
            if(str[L] - '0' == dint) {
                return 1;
            } else {
                return 0;
            }
        }
        int ret = 0;
        int len = R - L + 1;
        for(int i = L+1; i <= R-1; i = i + 2) {
            int LT = recursion(str, L, i-1, true) % modNum;
            int LF = recursion(str, L, i-1, false) % modNum;
            int RT = recursion(str, i+1, R, true) % modNum;
            int RF = recursion(str, i+1, R, false) % modNum;
            //i位置一定是运算符号 以此为分界
            if(str[i] == '^') {
                if(desire == true) {
                    //0 ^ 1 或者 1 ^ 0
                    ret += LF * RT % modNum;
                    ret += LT * RF % modNum;
                } else {
                    //0 ^ 0 或者 1 ^ 1
                    ret += LF * RF % modNum;
                    ret += LT * RT % modNum;
                }
            } else if(str[i] == '&') {
                if(desire == true) {
                    //1 & 1
                    ret += LT * RT % modNum;
                } else {
                    //0 & 0 或者 0 & 1 或者 1 & 0
                    ret += LF * RF % modNum;
                    ret += LF * RT % modNum;
                    ret += LT * RF % modNum;
                }
            } else if(str[i] == '|') {
                if(desire == true) {
                    //1 | 1 或者 1 | 0 或者 0 | 1
                    ret += LT * RT % modNum;
                    ret += LT * RF % modNum;
                    ret += LF * RT % modNum;
                } else {
                    //0 | 0
                    ret += LF * RF % modNum;
                }
            }
        }
        return ret;
    }

    //动态规划
    int dynamicPlan(const string& str, bool desire) {
        //测试
        for(int i = 0; i < 505; i++) {
            for(int j = 0; j < 505; j++) {
                dp[0][i][j] = 0;
                dp[1][i][j] = 0;
            }
        }

        //目标 返回dp[desire][0][len-1]
        int len = str.length();
        //初始化对角线
        for(int i = 0; i < len; i = i+2) {
            //对于每个i~i,定义返回方案数
            if(str[i] == '0') {
                dp[0][i][i] = 1;
                dp[1][i][i] = 0;
            } else if(str[i] == '1'){
                dp[0][i][i] = 0;
                dp[1][i][i] = 1;
            } else {
                //非法输入 退出
                return 0;
            }
        }
        //补足其他区域
        //行 从下到上
        for(int i = len-1; i >= 0; i = i-2) {
            for(int j = 0; j < len; j = j+2) {
                //在[i,j]之间遍历 i,j相当于之前的L,R
                for(int k = i+1; k <= j-1; k = k+2) {
                    // cout << i << " " << j << endl;
                    long long int LT = dp[1][i][k-1];
                    long long int LF = dp[0][i][k-1];
                    long long int RT = dp[1][k+1][j];
                    long long int RF = dp[0][k+1][j];
                    // cout << "LT:" << LT << endl;
                    // cout << "LF:" << LF << endl;
                    // cout << "RT:" << RT << endl;
                    // cout << "RF:" << RF << endl;
                    // cout << "i:" << i << " j:" << j << " k:" << k << endl;
                    if(LT == -1 || LF == -1 || RT == -1 || RF == -1) {
                        cout << "error" << endl;
                        // exit(-1);
                    }
                    long long int r00 = (LF * RF) % modNum; 
                    long long int r01 = (LF * RT) % modNum; 
                    long long int r10 = (LT * RF) % modNum; 
                    long long int r11 = (LT * RT) % modNum; 
                    if(str[k] == '^') {
                            //0 ^ 1 或者 1 ^ 0
                            dp[1][i][j] += r01;
                            dp[1][i][j] %= modNum;
                            dp[1][i][j] += r10;
                            dp[1][i][j] %= modNum;
                            //0 ^ 0 或者 1 ^ 1
                            dp[0][i][j] += r00;
                            dp[0][i][j] %= modNum;
                            dp[0][i][j] += r11;
                            dp[0][i][j] %= modNum;
                    } else if(str[k] == '&') {
                            //1 & 1
                            dp[1][i][j] += r11;
                            dp[1][i][j] %= modNum;
                            //0 & 0 或者 0 & 1 或者 1 & 0
                            dp[0][i][j] += r00;
                            dp[0][i][j] %= modNum;
                            dp[0][i][j] += r01;
                            dp[0][i][j] %= modNum;
                            dp[0][i][j] += r10;
                            dp[0][i][j] %= modNum;
                    } else if(str[k] == '|') {
                            //1 | 1 或者 1 | 0 或者 0 | 1
                            dp[1][i][j] += r11;
                            dp[1][i][j] %= modNum;
                            dp[1][i][j] += r10;
                            dp[1][i][j] %= modNum;
                            dp[1][i][j] += r01;
                            dp[1][i][j] %= modNum;
                            //0 | 0
                            dp[0][i][j] += r00;
                            dp[0][i][j] %= modNum;
                    } else {
                        //非法输入 退出
                        return 0;
                    }
                    dp[0][i][j] %= modNum;
                    dp[1][i][j] %= modNum;
                    // cout << dp[1][i][j] << " " << dp[0][i][j] << endl;
                }
            }
        }
        // char d = '\t';
        // cout << "-----------------true-----------------" << endl;
        // for(int i = 0; i < len; i++) {
        //     for(int j = 0; j < len; j++) {
        //         if(i <= j)
        //             cout << dp[1][i][j] << d;
        //         else    
        //             cout << d;
        //     }
        //     cout << endl;
        // }
        // cout << "-----------------false-----------------" << endl;
        // for(int i = 0; i < len; i++) {
        //     for(int j = 0; j < len; j++) {
        //         if(i <= j)
        //             cout << dp[0][i][j] << d;
        //         else    
        //             cout << d;
        //     }
        //     cout << endl;
        // }
        if(desire) {
            return dp[1][0][len-1];
        } else {
            return dp[0][0][len-1];
        }
    }
};

int main() {
    // ifstream in("in.txt");
    // string str,desire;
    // in >> str >> desire;
    // Solution().getNum(str,desire);

    string str,desire;
    cin >> str >> desire;
    int ret = Solution().getNum(str,desire);
    return 0;
}